package com.jbit.dm212.controller;

import cn.hutool.core.bean.BeanUtil;
import com.jbit.dm212.common.ResponseResult;
import com.jbit.dm212.common.ResponseResultUtils;
import com.jbit.dm212.entity.dto.DmOrderInfoDTO;
import com.jbit.dm212.entity.dto.DmOrderSearchDTO;
import com.jbit.dm212.entity.po.DmOrder;
import com.jbit.dm212.entity.vo.DmOrderSearchVO;
import com.jbit.dm212.entity.vo.DmOrderVO;
import com.jbit.dm212.service.DmOrderService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

@RestController
@RequestMapping("/order/api/v")
public class DmOrderVerifyController {
    static ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(10);
    @Resource
    private DmOrderService orderService;
    @PostMapping("/createOrder")
    public ResponseResult createOrder(@RequestBody DmOrderVO orderVO){
        DmOrder order = orderService.createOrder(orderVO);
        scheduledExecutorService.schedule(()->{
            System.out.println(order + ":" + LocalDateTime.now());
        },30, TimeUnit.SECONDS);
        return ResponseResultUtils.sendSuccess(order);
    }
    @PostMapping("/queryOrderList")
    public ResponseResult queryOrderList(@RequestBody DmOrderSearchVO orderSearchVO){
        List<DmOrderSearchDTO> orderSearchDTOList = orderService.getOrderInfo(orderSearchVO);
        return ResponseResultUtils.sendSuccess(orderSearchDTOList);
    }

    @PostMapping("/queryOrderByOrderNo")
    public ResponseResult queryOrderByOrderNo(@RequestBody DmOrder order){
        DmOrderInfoDTO orderInfoDTO = orderService.getOrderInfoByOrderNo(order.getOrderNo());
        return ResponseResultUtils.sendSuccess(orderInfoDTO);
    }
}
